﻿using System;
using System.Collections.Generic;
using System.Text;

namespace _017_字段_属性_索引器_常量_4_
{
    internal class Program
    {
        static void Main(string[] args)
        {

            try
            {
                Student stu = new Student();
                stu.SomeMethod();
                Console.WriteLine(stu.Age);
                Console.WriteLine(stu.CanWork);
                //stu.Age = 1000;
            }
            catch (Exception ex)
            {

                Console.WriteLine(ex.Message);
            }
        }
    }

    class Student
    {
        private int age;

        private int amount;



        public int Age
        {
            get { return age; }
            private set
            {
                age = value;
                this.CalculateWork();
            }
        }

        public void SomeMethod()
        {
            this.Age = 20;
        }


        private bool canWork;
        //只读属性
        public bool CanWork
        {
            get
            {
                return canWork;
            }

        }

        public void CalculateWork()
        {
            if (this.age >= 16)
            {
                this.canWork = true;
            }
            else
            {
                this.canWork = false;
            }
        }
    }
}
